using System;
using System.Drawing;

namespace ExcelTemplateEngine.Models.TemplateModels
{
    /// <summary>
    /// 完整的单元格样式信息
    /// </summary>
    public class FullCellStyle
    {
        /// <summary>
        /// 字体信息
        /// </summary>
        public FontInfo Font { get; set; }
        
        /// <summary>
        /// 填充信息
        /// </summary>
        public FillInfo Fill { get; set; }
        
        /// <summary>
        /// 边框信息
        /// </summary>
        public BorderInfo Border { get; set; }
        
        /// <summary>
        /// 对齐信息
        /// </summary>
        public AlignmentInfo Alignment { get; set; }
        
        /// <summary>
        /// 数字格式
        /// </summary>
        public string? NumberFormat { get; set; }
        
        /// <summary>
        /// 是否锁定
        /// </summary>
        public bool IsLocked { get; set; }
        
        /// <summary>
        /// 是否隐藏
        /// </summary>
        public bool IsHidden { get; set; }
        
        /// <summary>
        /// 构造函数
        /// </summary>
        public FullCellStyle()
        {
            Font = new FontInfo();
            Fill = new FillInfo();
            Border = new BorderInfo();
            Alignment = new AlignmentInfo();
        }
        
        /// <summary>
        /// 克隆样式
        /// </summary>
        public FullCellStyle Clone()
        {
            return new FullCellStyle
            {
                Font = Font?.Clone() ?? new FontInfo(),
                Fill = Fill?.Clone() ?? new FillInfo(),
                Border = Border?.Clone() ?? new BorderInfo(),
                Alignment = Alignment?.Clone() ?? new AlignmentInfo(),
                NumberFormat = NumberFormat,
                IsLocked = IsLocked,
                IsHidden = IsHidden
            };
        }
    }
    
    /// <summary>
    /// 字体信息
    /// </summary>
    public class FontInfo
    {
        public string Name { get; set; } = "Calibri";
        public double Size { get; set; } = 11;
        public bool Bold { get; set; }
        public bool Italic { get; set; }
        public bool Underline { get; set; }
        public Color Color { get; set; } = Color.Black;
        
        public FontInfo Clone() => (FontInfo)MemberwiseClone();
    }
    
    /// <summary>
    /// 填充信息
    /// </summary>
    public class FillInfo
    {
        public FillType Type { get; set; } = FillType.None;
        public Color BackgroundColor { get; set; } = Color.White;
        public Color ForegroundColor { get; set; } = Color.Black;
        public FillPattern Pattern { get; set; } = FillPattern.Solid;
        
        public FillInfo Clone() => (FillInfo)MemberwiseClone();
    }
    
    /// <summary>
    /// 边框信息
    /// </summary>
    public class BorderInfo
    {
        public BorderStyle Left { get; set; }
        public BorderStyle Right { get; set; }
        public BorderStyle Top { get; set; }
        public BorderStyle Bottom { get; set; }
        public BorderStyle Diagonal { get; set; }
        public bool DiagonalUp { get; set; }
        public bool DiagonalDown { get; set; }
        
        public BorderInfo Clone() => (BorderInfo)MemberwiseClone();
    }
    
    /// <summary>
    /// 对齐信息
    /// </summary>
    public class AlignmentInfo
    {
        public HorizontalAlignment Horizontal { get; set; } = HorizontalAlignment.General;
        public VerticalAlignment Vertical { get; set; } = VerticalAlignment.Center;
        public int Indent { get; set; }
        public bool WrapText { get; set; }
        public bool ShrinkToFit { get; set; }
        public int TextRotation { get; set; }
        
        public AlignmentInfo Clone() => (AlignmentInfo)MemberwiseClone();
    }
    
    public enum FillType { None, Solid, Pattern }
    public enum FillPattern { Solid, Gray125, Gray0625 }
    public enum BorderStyle { None, Thin, Medium, Thick, Double }
    public enum HorizontalAlignment { General, Left, Center, Right, Fill, Justify }
    public enum VerticalAlignment { Top, Center, Bottom, Justify }
}